﻿using App.Models;
using Microsoft.Extensions.Options;

namespace App.Services
{
    public class GreetingV2Service : IGreetingService
    {
        private readonly Greeting _greeting;
        private readonly ILogger<GreetingV2Service> _logger;
        public GreetingV2Service(IOptions<Greeting> optionsAccessor, ILogger<GreetingV2Service> logger)
        {
            _greeting = optionsAccessor.Value;
            _logger = logger;
        }
        public string Greeting(DateTimeOffset time)
        {
            var message = time.Hour switch
            {
                var h when h >= 5 && h < 12 => _greeting.Morning,
                var h when h >= 12 && h < 17 => _greeting.Afternooning,
                _ => _greeting.Evening
            };

            _logger.LogInformation("{time}=>{message}", time, message);
            return message;
        }
    }
}
